package com.huizu.project.controller;

import com.huizu.common.annotation.Anonymous;
import com.huizu.common.core.controller.BaseController;
import com.huizu.common.core.domain.AjaxResult;
import com.huizu.common.core.domain.entity.SysUser;
import com.huizu.common.core.page.TableDataInfo;
import com.huizu.common.utils.SecurityUtils;
import com.huizu.common.utils.dx.SecurityUtil;
import com.huizu.project.domain.BaseVo;
import com.huizu.project.domain.ProUserDc;
import com.huizu.project.domain.ProUserSchoolDcVo;
import com.huizu.project.service.IProUserDcService;
import com.huizu.project.service.IProXyService;
import com.huizu.project.service.impl.ProUserDcServiceImpl;
import com.huizu.project.utils.TokenUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Anonymous
@RestController
@RequestMapping("/project/prouserxjdc")
public class ProUserSchoolDcController extends BaseController {

    @Autowired
    private IProXyService proXyService;

    @Autowired
    private IProUserDcService proUserDcService;


    /**
     * 获取督促学院列表
     * @param proUserSchoolDcVo
     * @return
     */
//    @PreAuthorize("@ss.hasPermi('project:prouserxjdc:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProUserSchoolDcVo proUserSchoolDcVo) {
        startPage();
        String id = proUserSchoolDcVo.getId();
        BaseVo baseVo = proXyService.getSchoolDcList(id);
        TableDataInfo dataTable = getDataTable(baseVo.getList());
        dataTable.setTotal(baseVo.getTotal());
        return dataTable;
    }

    /**
     * 获取督促详情
     * @param id
     * @return
     */
    @PreAuthorize("@ss.hasPermi('project:prouserxjdc:query')")
    @GetMapping("/{id}")
    public AjaxResult getDetail(@PathVariable("id") String id) {
        ProUserSchoolDcVo proUserSchoolDcVo = proXyService.getDetail(id);
        return success(proUserSchoolDcVo);
    }

    /**
     * 增肌督促内容
     * @param proUserDc
     * @param request
     * @return
     */
    @PreAuthorize("@ss.hasPermi('project:prouserxjdc:add')")
    @PostMapping("/create")
    public AjaxResult create(@RequestBody ProUserDc proUserDc, HttpServletRequest request) {
        SysUser user = SecurityUtils.getLoginUser().getUser();
        proUserDc.setTerId(user.getUserId().toString());
        int row = proUserDcService.createDcXj(proUserDc);
        return toAjax(row);
    }

}
